package top.zlhy7.exception;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * @author renyong
 * @date 2024/9/29 19:27
 * @description 服务端异常
 */
@NoArgsConstructor
@Data
public class ServiceException extends RuntimeException{
    /**
     * 错误信息提示
     */
    private String errMsg = "服务端异常，请稍后再试";
    /**
     * 错误码
     */
    private int errCode = HttpStatus.INTERNAL_SERVER_ERROR.value();

    public ServiceException(String errMsg) {
        super(errMsg);
        this.errMsg = errMsg;
    }

    public ServiceException(String errMsg, int errCode) {
        super(errMsg);
        this.errMsg = errMsg;
        this.errCode = errCode;
    }
    public ServiceException format(CharSequence template, Object... params){
        return new ServiceException(StrUtil.format(template,params));
    }
}
